package org.example.tree.binary;

import org.example.tree.entity.BinaryTreeNode;

/**
 * @author zjt
 * @description
 * @date 2024/1/30 09:32
 */
public class BinaryTree {

    public static void main(String[] args) {
        BinaryTreeNode root = new BinaryTreeNode(0);
        root.left = new BinaryTreeNode(1);
        root.right = new BinaryTreeNode(2);
        root.left.left = new BinaryTreeNode(3);
        root.left.right = new BinaryTreeNode(4);
        root.right.left = new BinaryTreeNode(6);
        root.right.right = new BinaryTreeNode(5);
        BinaryTreeTraversal binaryTreeTraversal = new BinaryTreeTraversal();
        //根据根节点遍历的顺序称为前中后序遍历
        //前序遍历，先遍历根节点，再遍历左右
        System.out.println("前序遍历");
        binaryTreeTraversal.preorderTraversal(root);
        //结果为013425
        //中序遍历，先遍历左节点，再遍历根节点和右节点
        System.out.println("中序遍历");
        binaryTreeTraversal.inorderTraversal(root);
        //结果为314025
        //后序遍历，先遍历左右节点，再遍历根节点
        System.out.println("后序遍历");
        binaryTreeTraversal.postorderTraversal(root);
        //结果为341520
        //层序遍历为012345
        System.out.println("层序遍历");
        binaryTreeTraversal.levelOrderTraversal(root);
    }
}
